package Impl;

import bb.Node;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Julien
 * Date: 18/03/14
 * Time: 10:20
 * To change this template use File | Settings | File Templates.
 */
public class Knapsack {
    public static final int nbsac = 2;

    public static final Objet obj1 = new Objet(5, 20);
    public static final Objet obj2 = new Objet(12, 25);
    public static final Objet obj3 = new Objet(3, 8);
    public static final Objet obj4 = new Objet(7, 12);

    public static final Sac sac1 = new Sac(14);
    public static final Sac sac2 = new Sac(7);

    public List<Objet> objetList = new ArrayList<Objet>();
    public List<Sac> sacList = new ArrayList<Sac>();

    public Knapsack() {
        objetList.add(obj1);
        objetList.add(obj2);
        objetList.add(obj3);
        objetList.add(obj4);
        sacList.add(sac1);
        sacList.add(sac2);
        Collections.sort(objetList);
    }

    public float getUpperBound() {
        float upperBound = 0;
        float limit = 0;
        int i = 0;
        for (Sac sac : sacList) {
            limit += sac.getvolume();
        }
        for (Objet o : objetList) {
            if (limit > o.getpoidss()) {
                System.out.println(o);
                upperBound += o.getUtil();
                System.out.println(upperBound);
                limit -= o.getpoidss();
                i++;
            } else if (limit > 0) {
                upperBound += (limit) * o.getRapportPU();
                limit = 0;
            }
        }
        return upperBound;
    }

    class NodeTest extends Node {
        @Override
        public int getCost() {
            return 0;
        }

        @Override
        public int getEval() {
            return 0;
        }

        @Override
        public boolean isBetter(int s) {
            return false;
        }

    }

    public static void main(String[] args) {
        Knapsack knapsack = new Knapsack();
        System.out.println(knapsack.getUpperBound());
    }
}
